
package com.zp.master.modules.impl;



import com.zp.master.modules.dao.SysRoleDao;
import com.zp.master.modules.entity.SysRole;
import com.zp.master.modules.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service(value = "SysRoleService")
public class SysRoleImpl implements SysRoleService {

    @Autowired
    private SysRoleDao sysRoleDao;

    @Override
    public Object insert(Object entity) {
        return null;
    }

    @Override
    public void insertList(List entities) {

    }

    @Override
    public boolean removeByPrimaryKey(Object primaryKey) {
        return false;
    }

    @Override
    public boolean update(Object entity) {
        return false;
    }

    @Override
    public boolean updateSelective(Object entity) {
        return false;
    }

    @Override
    public Object getByPrimaryKey(Object primaryKey) {
        return null;
    }

    @Override
    public Object getOneByEntity(Object entity) {
        return null;
    }

    @Override
    public List listAll() {
        return null;
    }

    @Override
    public List listByEntity(Object entity) {
        return null;
    }

    /**
     * 查询角色内容
     * @param name
     * @return
     */
    public Set<String> getDescription (String name){
        Set<String> descriptionSet = sysRoleDao.getDescription(name);
        return descriptionSet;
    }

    /**
     * 获取用户的角色
     * @param userId
     * @return
     */
    @Override
    public List<SysRole> listRolesByUserId(Long userId) {
        List<SysRole> sysRoles = sysRoleDao.listRolesByUserId(userId);
        if (CollectionUtils.isEmpty(sysRoles)) {
            return null;
        }
        List<SysRole> roles = new ArrayList<>();
        for (SysRole r : sysRoles) {
            roles.add(new SysRole(r));
        }
        return roles;
    }

    ;
}
